package com.czy.fx.day1.pane.Box;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class demo2 extends Application {

    static boolean managed = false;
    static boolean visible = false;
    static double opacityValue = 0.0;

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setTitle("标题");
        primaryStage.setWidth(800);
        primaryStage.setHeight(800);
        AnchorPane anchorPane = new AnchorPane();
        primaryStage.setScene(new Scene(anchorPane));

        anchorPane.setStyle("-fx-background-color: #EE1169");

        //水平布局
        HBox box = new HBox();
        box.setPrefWidth(300);
        box.setPrefHeight(100);
        box.setStyle("-fx-background-color: #27EE11FF");
        box.setPadding(new Insets(20));
        //box.setSpacing(10);
        anchorPane.getChildren().add(box);

        Button b1 = new Button("b1");
        Button b2 = new Button("b2");
        Button b3 = new Button("b3");
        Button b4 = new Button("b4");
        box.getChildren().addAll(b1, b2, b3, b4);
        //子控件居中
        box.setAlignment(Pos.CENTER);

        //垂直布局
        VBox vbox = new VBox();
        vbox.setAlignment(Pos.CENTER);
        vbox.setPrefWidth(200);
        vbox.setPrefHeight(300);
        box.setStyle("-fx-background-color: #EEDC11FF");
        anchorPane.getChildren().add(vbox);

        Button b5 = new Button("b3.setManaged(false);");
        Button b6 = new Button("b3.setVisible(false);");
        Button b7 = new Button("b3.setOpacity(0);");
        vbox.getChildren().addAll(b5, b6, b7);

        b5.setOnMouseClicked((event)->{
            if (managed){
                managed = false;
            }else{
                managed = true;
            }
            b3.setManaged(managed);
            b5.setText("b3.setManaged("+managed+");");
        });

        b6.setOnMouseClicked((event)->{
            if (visible){
                visible = false;
            }else{
                visible = true;
            }
            b3.setVisible(visible);
            b6.setText("b3.setVisible("+visible+");");
        });
        b7.setOnMouseClicked((event)->{
            if (opacityValue == 0){
                opacityValue = 1;
            }else{
                opacityValue = 0;
            }
            b3.setOpacity(opacityValue);
            b7.setText("b3.setOpacity("+opacityValue+");");
        });
        //响应式布局 管理子组件的位置，设置上边界距离
        primaryStage.show();
    }
}
